/**
 * @(#)ItemDao.java, 2018/2/2.
 * <p/>
 * Copyright 2018 Kerr Wang, Inc. All rights reserved.
 * KERRWANG PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 */
package org.wangzx.exercise.dao;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Repository;
import org.wangzx.exercise.meta.po.Item;

/**
 * @author hzwangzuxiang(ahscwzx@163.com)
 */
@Repository("itemDao")
public class ItemDao extends AbstractDao<Item> {
    public Item getById(long id) {
        Map<String, Object> map = new HashMap<>();
        map.put("id", id);
        return sqlSessionTemplate.selectOne(classStr + ".getById", map);
    }

    public List<Item> getItemsByPage(long pageStart, long pageSize) {
        Map<String, Object> map = new HashMap<>();
        map.put("pageStart", pageStart);
        map.put("pageSize", pageSize);
        return sqlSessionTemplate.selectList(classStr + ".getItemsByPage", map);
    }

    public List<Item> getItemsBySeller(long sellerId) {
        Map<String, Object> map = new HashMap<>();
        map.put("publisher", sellerId);
        return sqlSessionTemplate.selectList(classStr + ".getItemsBySeller", map);
    }

    public boolean updateItem(Item item) {
        return sqlSessionTemplate.update(classStr + ".updateItem", item) > 0;
    }

    public boolean addSellerCount(long id, int num) {
        Map<String, Object> map = new HashMap<>();
        map.put("id", id);
        map.put("num", num);
        return sqlSessionTemplate.update(classStr + ".addSellerCount", map) > 0;
    }
}
